﻿using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;

namespace JwtDemo.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {


        public string GetToken()
        {
            // 3 + 2
            SecurityToken securityToken = new JwtSecurityToken(
                issuer: "issuer",
                audience: "audience",
                signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes("sealeesealeesealeesealeesealeesealeesealee")), SecurityAlgorithms.HmacSha256),
                expires: DateTime.Now.AddHours(1),
                claims: new Claim[] {
                    new Claim("sealee","laoli"),
                    new Claim(ClaimTypes.Role,"User"),
                    new Claim(ClaimTypes.Role,"Admin"),
                    new Claim(ClaimTypes.Email,"Admin@qq.com"),
                }
            );
            return new JwtSecurityTokenHandler().WriteToken(securityToken);
        }

    }
}